package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.ClazzLog;
import com.briup.srms.sms.dao.ClazzLogMapper;
import com.briup.srms.sms.dao.extend.ClazzLogExtendMapper;
import com.briup.srms.sms.service.IClazzLogService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class ClazzLogServiceImpl implements IClazzLogService {

	@Autowired
	private ClazzLogMapper clazzLogMapper;
	@Autowired
	private ClazzLogExtendMapper clazzLogExtendMapper;

	@Override
	public ClazzLog findClazzLog(String logDate, Long clazzId) {
		List<ClazzLog> list = clazzLogExtendMapper.query(1, 10,logDate,clazzId);
		//if(list.size()>0) {
		//	return list.get(0);
		//}
		return null;
	}

	@Override
	public PageVM<ClazzLog> pageQuery(int page, int pageSize,String logDate,Long clazzId) {
		List<ClazzLog> list = clazzLogExtendMapper.query(page, pageSize,logDate,clazzId);
		long total = clazzLogExtendMapper.count(logDate,clazzId);
		return new PageVM<>(page, pageSize, total, list);
	}
	@Override
	public void saveOrUpdate(ClazzLog clazzLog) {
		if(clazzLog.getId() == null) {
			clazzLogMapper.insert(clazzLog);
		} else {
			clazzLogMapper.updateByPrimaryKey(clazzLog);
		}

	}
	@Override
	public void deleteById(long id) {
		ClazzLog dict = clazzLogMapper.selectByPrimaryKey(id);
		if(dict == null) {
			throw new CustomerException("要删除的数据不存在");
		}
		clazzLogMapper.deleteByPrimaryKey(id);

	}
}
